<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="/jsp/common/common.jsp" %>
<%
	String domainId = request.getAttribute("domainId") == null?"":request.getAttribute("domainId").toString();
	String groupId = request.getAttribute("groupId") == null?"":request.getAttribute("groupId").toString();
%>
</head>
<body>

<div class="tableMainWarp">
 <table border="0" cellspacing="0" cellpadding="0" width="90%" class="group-table">
 	<tr>
 		<td width="4%" align="center"><input type="radio" name="scope" value="all" /></td>
 		<td width="96%"><span name="text0">所有人员</span></td>
 	</tr>
 	<tr>
 		<td><input type="radio" name="scope" value="orgInside" /></td>
 		<td>
 			<select name="takePart">
 				<option value="submiter">提交人</option>
 				<option value="drafter">起草人</option>
 			</select>&nbsp;
 			<span name="text0">所在组织的</span>&nbsp;
 			<select class="table-input" name="positionId" style="width: 30%;"></select>
		</td>
 	</tr>
 	<tr>
 		<td align="center"><input type="radio" name="scope" value="orgUp" /></td>
 		<td>
 			<select name="takePart">
 				<option value="submiter">提交人</option>
 				<option value="drafter">起草人</option>
 			</select>&nbsp;
 			<span name="text0">所在组织的上一级组织的</span>&nbsp;
 			<select class="table-input" name="positionId" style="width: 30%;"></select>
		</td>
 	</tr>
 	<tr>
 		<td align="center"><input type="radio" name="scope" value="orgDown" /></td>
 		<td>
 			<select name="takePart">
 				<option value="submiter">提交人</option>
 				<option value="drafter">起草人</option>
 			</select>&nbsp;
 			<span name="text0">所在组织及其下级组织</span>&nbsp;
 			<select class="table-input" name="positionId" style="width: 30%;"></select>
		</td>
 	</tr>
 	<tr>
 		<td align="center"><input type="radio" name="scope" value="orgFix" /></td>
 		<td>
 			<span name="text0">指定组织内的</span>&nbsp;
 			<span name="orgName"></span>&nbsp;
 			<button class="btn-table" id="selectOrgButton">选择机构</button>
 			<input type="hidden" id="orgId" value="" />
 			<select class="table-input" name="positionId" style="width: 30%;"></select>
		</td>
 	</tr>
 	<tr>
 		<td align="center"><input type="radio" name="scope" value="orgDown" /></td>
 		<td>
 			<span name="text0">指定组织及其下级组织内的</span>&nbsp;
 			<span name="orgName1"></span>&nbsp;
 			<button class="btn-table" id="selectOrgButton1">选择机构</button>
 			<input type="hidden" id="orgId1" value="" />
 			<select class="table-input" name="positionId" style="width: 30%;"></select>
		</td>
 	</tr>
 </table>
</div>

<script type="text/javascript">

$(document).ready(function(){
	
	var bodyHt=document.documentElement.clientHeight;
	var tableDivHeight = bodyHt-97;	
	//$('#middleCon').height(tableDivHeight);
	
	getPageData();

	
});

function getPageData(){
	var url = '<%=basePath%>/biz/ou/employee/getAllPositionList.do?domainId=<%=domainId %>';
	var array = $('body').find('select[name="positionId"]');
	initSelectDataBatch(url, array,'positionName','id','所有人员');
	
	$('#selectOrgButton').on('click',function(){
		organizationSelectTree('<%=basePath%>', '<%=domainId%>', function(pageData,layer){
			$('#orgId').val(pageData[0].id);
			$('span[name="orgName"]').html(pageData[0].name);
			layer.close();
		});
	});
	
	$('#selectOrgButton1').on('click',function(){
		organizationSelectTree('<%=basePath%>', '<%=domainId%>', function(pageData,layer){
			$('#orgId1').val(pageData[0].id);
			$('span[name="orgName1"]').html(pageData[0].name);
			layer.close();
		});
	});
}



function onConfrim(layerObject,tablegridGobalObject){
	
	var url = '<%=basePath%>/biz/ou/group/addFormulaToGroup.do?domainId=<%=domainId %>';
    var jsonData = packagePageData();
	
	var jsonDataStr = JSON.stringify(jsonData);
	
	$.ajax({
		url : url,
		type : 'post',
		dataType : 'json',
		data:{jsonData:jsonDataStr},
		success : function(data, textStatus, jqXHR) {
			showAlert('添加成功',function(){
				layerObject.close();
				tablegridGobalObject.reload();
			});
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
		}
	});
	
}
/**
 * 封装页面数据 
 *
 */
function packagePageData(){
	
	var typeObj = $('input:radio[name="scope"]:checked');
	var trObj = $(typeObj).parent().parent();
	var type = $(typeObj).val();
	
	var pageData = {
		groupId:'<%=groupId%>',
		formulaType : type
	};
	
	
	if(type == 'all'){//所有人员
		pageData.name = $(trObj).find('span[name="text0"]').html();
	}else if(type == 'orgInside'){//所在组织的
		
		var takePartName = $(trObj).find('select[name="takePart"] option:selected').text();
		var positionName = $(trObj).find('select[name="positionId"] option:selected').text();
		
		var name = takePartName + $(trObj).find('span[name="text0"]').html()+positionName;
		
		pageData.name = name;
		pageData.takePart = $(trObj).find('select[name="takePart"]').val();
		pageData.positionId = $(trObj).find('select[name="positionId"]').val();
		
	}else if(type == 'orgUp'){//所在组织的上一级组织的

		var takePartName = $(trObj).find('select[name="takePart"] option:selected').text();
		var positionName = $(trObj).find('select[name="positionId"] option:selected').text();
		
		var name = takePartName + $(trObj).find('span[name="text0"]').html()+positionName;
		
		pageData.name = name;
		pageData.takePart = $(trObj).find('select[name="takePart"]').val();
		pageData.positionId = $(trObj).find('select[name="positionId"]').val();
	}else if(type == 'orgDown'){//所在组织及其下级组织

		var takePartName = $(trObj).find('select[name="takePart"] option:selected').text();
		var positionName = $(trObj).find('select[name="positionId"] option:selected').text();
		
		var name = takePartName + $(trObj).find('span[name="text0"]').html()+positionName;
		
		pageData.name = name;
		pageData.takePart = $(trObj).find('select[name="takePart"]').val();
		pageData.positionId = $(trObj).find('select[name="positionId"]').val();
	}else if(type == 'orgFix'){//指定组织内的
		var positionName = $(trObj).find('select[name="positionId"] option:selected').text();
		pageData.name = $(trObj).find('span[name="orgName"]').html()+'下的'+positionName;
		pageData.orgId = $(trObj).find('input[id="orgId"]').val();
		pageData.positionId = $(trObj).find('select[name="positionId"]').val();
	}else if(type == 'orgFixDown'){//指定组织及其下级组织内的
		var positionName = $(trObj).find('select[name="positionId"] option:selected').text();
		pageData.name = $(trObj).find('span[name="orgName1"]').html()+'及其下级组织内的'+positionName;
		pageData.orgId = $(trObj).find('input[id="orgId1"]').val();
		pageData.positionId = $(trObj).find('select[name="positionId"]').val();
	}
	
	return pageData;
}


</script>
</body>
</html>